<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/20
 * Time: 10:19
 */
namespace app\member\controller;
use think\Db;
use think\Session;
use think\Config;
use think\Request;
use think\Loader;
use app\common\controller\simple_html_dom;
use app\member\model\Balance as BalanceModel;
use app\member\model\Changedoc as ChangedocModel;
class Order extends Common
{
	public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
		parent::checktype();
    }
    /**
     * 订单列表
     */
    public function index()
    {
        session('MenuCookie','2');
        $UrlParam=input();
        $where=array();
        if(!empty($UrlParam['order'])) $where['A.order_number'] = ['like','%'.$UrlParam['order'].'%'];
        if(!empty($UrlParam['title'])) $where['W.article_title'] = ['like','%'.$UrlParam['title'].'%'];
		if(!empty($UrlParam['article_customer'])) $where['W.article_customer'] = ['like','%'.$UrlParam['article_customer'].'%'];		
        if(isset($UrlParam['status']) && $UrlParam['status']>='0'){			
			$where['A.order_state'] = $UrlParam['status'];
		}else{
			$UrlParam['status']=-1;
		}
        $StartDate = input('startdate', '');
        $EndDate = input('enddate', '');
        if(!empty($StartDate) || !empty($EndDate)){
            if(empty($StartDate)) $StartDate=date('Y-m-d');
            if(empty($EndDate)) $EndDate=date('Y-m-d');
        }
        if(!empty($StartDate) && !empty($EndDate)){
            $StartDate=strtotime($StartDate);$EndDate=strtotime($EndDate);
            $MinDate=min($StartDate,$EndDate);$MaxDate=max($StartDate,$EndDate);
            $MaxDate+=86399;
            $UrlParam['startdate']=date('Y-m-d',$MinDate);
            $UrlParam['enddate']=date('Y-m-d',$MaxDate);
            $UrlParam['MinDate']=$MinDate;$UrlParam['MaxDate']=$MaxDate;
        }
        if(!empty($UrlParam['MinDate']) && !empty($UrlParam['MaxDate'])){
            $where['A.order_time']=array('between',[$UrlParam['MinDate'],$UrlParam['MaxDate']]);
        }
        $where['W.member_id']=$this->MemberID;
        $where['A.RegDomain']=$this->AgencySiteInfo['Domain'];
		$where['A.media_type']=1;
        $List =  Db::name('agencyorder')
            ->alias('A')
            ->field('A.*,W.article_title,W.article_customer,M.MediaTitle,M.UserType,W1.TypeName as mtmc')
            ->join('article W', 'W.article_id=A.article_id', 'left')
            ->join('media M', 'M.MediaID=A.media_id', 'left')
			->join('wholetype W1', 'W1.TypeID=M.MediaWebNameID', 'left')//频道类型
            ->where($where)
            ->order('A.order_time desc')
            ->paginate(20,true,['query'  => $UrlParam]);
		//echo Db::name('agencyorder')->getLastsql();
		//die;
        $_SESSION['UrlParamOrder']=$UrlParam;
        $this->assign('UrlParam',$UrlParam);
        $this->assign('list',$List);
        return view();
    }
}